// var sortedArrayToBST = function (nums) {
//     const tree = (left, right) => {
//         if (left > right) {
//             return null
//         }
//         let mid = Math.floor((left + right) / 2)
//         let root = new TreeNode(nums[mid]);
//         root.left = tree(left, mid - 1)
//         root.right = tree(mid + 1, right)
//         return root
//     }
//     return tree(0, nums.length - 1)
// };

var sortedArrayToBST = function (nums) {
    function tree(left, right) {
        if (left > right) return null;

        let mid = Math.floor((left + right) / 2);
        let root = new TreeNode(nums[mid]);
        root.left = tree(left, mid - 1);
        root.right = tree(mid + 1, right);
        return root;
    }
    return tree(0, nums.length - 1);
}